<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Pjax;
use yii\widgets\LinkPager;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel frontend\modules\resource\models\SpecialSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '专题列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="hl-special-index">

    <div class="searchBody">

        <div class="addBtn">
            <?= Html::a('新增专题', 'javascript:;', ['class' => 'btn btn-success create']) ?>
        </div>
    </div>
    <?php Pjax::begin(['id' => 'centerView']); ?>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            'id',
            'title',
            //'sort',
            //'status',
            'created_at',
            'updated_at',
            //'deleted_at',
            'is_self' => [
                'attribute' => 'is_self',
                'value' => function ($model) {
                    return $model->is_self == 0 ? '系统分配资源':'自建资源';

                }
            ],
            //功能
            [
                'class' => 'frontend\modules\common\models\BranchActionJsColumn',
                'template' => '{update}{sp}{delete}{special-resource}',
            ]
        ],
        'pager' => [
            'class' => LinkPager::className(),
            'firstPageLabel' => '首页',
            'prevPageLabel' => '《',
            'nextPageLabel' => '》',
            'lastPageLabel' => '尾页',
            //            'goPageLabel' => true,
            //            'totalPageLable' => '共x页',
            //            'goButtonLable' => 'GO',
            'maxButtonCount' => 5,
            'hideOnSinglePage' => false,
        ]
    ]); ?>
    <?php Pjax::end(); ?>
</div>
<!--增删改 操作-->
<?php echo $this->render('../../../common/views/base/_column'); ?>
<script>
    <?php $this->beginBlock('js_block') ?>
    //资源列表
    $(document).on('click', '.special-resource', function () {
        var id = $(this).closest('tr').data('key');

        window.location.href = '<?=Url::toRoute('special-resource/index')?>'+'?sp_id=' + id;
    });
    //推荐隐藏
    $(document).on('click', '.sp', function () {
        var id = $(this).closest('tr').data('key');

        $.ajax({
            type: "POST",
            url: '<?=Url::toRoute('special-support')?>',
            data: {id: id},
            dataType: 'json'
        })
            .done(function (msg) {
                console.log(msg);
                if (msg['status'] == 200) {
                    layer.msg(msg['msg'], {icon: 1, time: 1000}, function () {
                        $.pjax.reload({container: "#centerView"});
                    });
                } else {
                    layer.msg(msg['msg'], {icon: 2});
                }
            });
    });
    <?php $this->endBlock() ?>
</script>
<?php $this->registerJs($this->blocks['js_block'], \yii\web\View::POS_END); ?>
